import tensorflow as tf

signature_key = tf.compat.v1.saved_model.signature_constants.DEFAULT_SERVING_SIGNATURE_DEF_KEY
input_key1 = 'input_x'
input_key2 = 'input_y'
output_key = 'output'
with tf.compat.v1.Session() as sess:
    meta_graph_def = tf.saved_model.loader.load(sess, [tf.compat.v1.saved_model.tag_constants.SERVING],"./demo3/half_plus")
    # 从meta_grapth_def中取出SignatureDef对象
    signature = meta_graph_def.signature_def
    v1_tensor_name = signature[signature_key].inputs[input_key1].name
    v2_tensor_name = signature[signature_key].inputs[input_key2].name
    output_tensor_name = signature[signature_key].outputs[output_key].name

    # 获取tensor
    v1 = sess.graph.get_tensor_by_name(v1_tensor_name)
    v2 = sess.graph.get_tensor_by_name(v2_tensor_name)
    output = sess.graph.get_tensor_by_name(output_tensor_name)
    print(sess.run(output,feed_dict={v1:[[2,4]],v2:[[3,6]]}))
